package com.business.exam.controller;

import com.business.common.core.controller.BaseController;
import com.business.common.core.domain.AjaxResult;
import com.business.common.core.page.TableDataInfo;
import com.business.exam.domain.ExamPaperModel;
import com.business.exam.domain.exam.ExamPaperAutoModel;
import com.business.exam.domain.exam.ExamPaperEditRequestVM;
import com.business.exam.domain.question.QuestionEditRequestVM;
import com.business.exam.service.IExamPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController("AdminExamPaperController")
@RequestMapping(value = "/api/admin/exam/paper")
public class ExamPaperController extends BaseController {

    @Autowired
    private IExamPaperService service;

    /**
     * 新增/修改信息
     */
    @PostMapping(value = "/saveOrEdit")
    public AjaxResult saveOrEdit(@RequestBody ExamPaperEditRequestVM dto) {
        // 存储数据
        service.saveOrEdit(dto);
        return AjaxResult.success("操作成功!");
    }


    /**
     * 根据ID查询工程信息
     */
    @PostMapping(value = "/findById")
    public AjaxResult findById(@RequestBody ExamPaperModel dto) {
        // 存储数据
        ExamPaperEditRequestVM resultData = service.findById(dto);
        return AjaxResult.success("操作成功!", resultData);
    }


    /**
     * 根据ID查询工程信息
     */
    @PostMapping(value = "/findByExamId")
    public AjaxResult findByExamId(@RequestBody ExamPaperModel dto) {
        // 存储数据
        ExamPaperEditRequestVM resultData = service.findById(dto);
        return AjaxResult.success("操作成功!", resultData);
    }


    /**
     * 查询工程信息列表
     */
    @RequestMapping(value = "/findPageList")
    public TableDataInfo findPageList(ExamPaperModel dto) {
        // 开始分页
        startPage();
        List<ExamPaperModel> list = service.findPage(dto);
        return getDataTable(list);
    }

    /**
     * 根据ID查询工程信息
     */
    @PostMapping(value = "/updateById")
    public AjaxResult updateById(@RequestBody Map<String, Object> paramMap) {
        // 存储数据
        service.updateById(paramMap);
        return AjaxResult.success("操作成功!");
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    public AjaxResult select(@PathVariable Integer id) {
        service.logicDelete(id);
        return AjaxResult.success("操作成功!");
    }

    /**
     * 自动生成试卷
     */
    @PostMapping(value = "/generatePaper")
    public AjaxResult generatePaper(@RequestBody ExamPaperAutoModel dto) {
        // 存储数据
        return  service.generatePaper(dto);
    }

}
